<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>控制流分析图</title>
    <style>
        body {
            margin: 0;
            padding: 20px;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            padding: 20px;
        }
        .header {
            text-align: center;
            margin-bottom: 20px;
            padding-bottom: 20px;
            border-bottom: 1px solid #eee;
        }
        .header h1 {
            color: #333;
            margin: 0;
            font-size: 24px;
        }
        .graph-container {
            width: 100%;
            height: 750px;
            border: 1px solid #ddd;
            border-radius: 4px;
            overflow: hidden;
        }
        .legend {
            margin-top: 20px;
            padding: 15px;
            background-color: #f8f9fa;
            border-radius: 4px;
        }
        .legend-item {
            display: inline-block;
            margin-right: 20px;
        }
        .legend-color {
            display: inline-block;
            width: 12px;
            height: 12px;
            margin-right: 5px;
            border-radius: 2px;
        }
        .controls {
            margin-top: 20px;
            padding: 15px;
            background-color: #f8f9fa;
            border-radius: 4px;
        }
        .control-group {
            margin-bottom: 10px;
        }
        .control-group:last-child {
            margin-bottom: 0;
        }
        .control-label {
            display: block;
            margin-bottom: 5px;
            font-weight: 500;
            color: #333;
        }
        .control-input {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            width: 100%;
            box-sizing: border-box;
        }
        .control-select {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            width: 100%;
            background-color: white;
        }
        .control-button {
            padding: 8px 16px;
            background-color: #2196F3;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.2s;
        }
        .control-button:hover {
            background-color: #1976D2;
        }
        .metrics {
            margin-top: 20px;
            padding: 15px;
            background-color: #f8f9fa;
            border-radius: 4px;
        }
        .metrics-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
            margin-top: 10px;
        }
        .metric-card {
            background-color: white;
            padding: 15px;
            border-radius: 4px;
            box-shadow: 0 1px 2px rgba(0,0,0,0.05);
        }
        .metric-card h3 {
            margin: 0;
            font-size: 14px;
            color: #666;
        }
        .metric-card p {
            margin: 5px 0 0;
            font-size: 24px;
            font-weight: 500;
            color: #2196F3;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>控制流分析图</h1>
        </div>
        
        <div class="graph-container">
            <!-- GRAPH_PLACEHOLDER -->
        </div>
        
        <div class="legend">
            <div class="legend-item">
                <span class="legend-color" style="background-color: #4CAF50;"></span>
                <span>开始节点</span>
            </div>
            <div class="legend-item">
                <span class="legend-color" style="background-color: #F44336;"></span>
                <span>结束节点</span>
            </div>
            <div class="legend-item">
                <span class="legend-color" style="background-color: #FF9800;"></span>
                <span>条件节点</span>
            </div>
            <div class="legend-item">
                <span class="legend-color" style="background-color: #2196F3;"></span>
                <span>循环节点</span>
            </div>
            <div class="legend-item">
                <span class="legend-color" style="background-color: #9C27B0;"></span>
                <span>顺序节点</span>
            </div>
        </div>
        
        <div class="controls">
            <div class="control-group">
                <label class="control-label">节点过滤</label>
                <input type="text" class="control-input" id="node-filter" 
                       placeholder="输入节点标签进行过滤">
            </div>
            <div class="control-group">
                <label class="control-label">节点类型</label>
                <select class="control-select" id="node-type">
                    <option value="all">全部</option>
                    <option value="start">开始节点</option>
                    <option value="end">结束节点</option>
                    <option value="condition">条件节点</option>
                    <option value="loop">循环节点</option>
                    <option value="sequence">顺序节点</option>
                </select>
            </div>
            <div class="control-group">
                <label class="control-label">复杂度阈值</label>
                <input type="number" class="control-input" id="complexity-threshold" 
                       value="10" min="1" max="100">
            </div>
            <div class="control-group">
                <button class="control-button" id="apply-filter">应用过滤</button>
                <button class="control-button" id="reset-filter" 
                        style="background-color: #666;">重置</button>
            </div>
        </div>
        
        <div class="metrics">
            <h2 style="margin: 0 0 15px 0; font-size: 18px;">控制流指标</h2>
            <div class="metrics-grid">
                <div class="metric-card">
                    <h3>节点总数</h3>
                    <p id="total-nodes">0</p>
                </div>
                <div class="metric-card">
                    <h3>条件分支数</h3>
                    <p id="condition-branches">0</p>
                </div>
                <div class="metric-card">
                    <h3>循环数量</h3>
                    <p id="loop-count">0</p>
                </div>
                <div class="metric-card">
                    <h3>平均复杂度</h3>
                    <p id="avg-complexity">0</p>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        // 过滤功能的实现将由Python生成的网络图JS代码处理
        document.getElementById('apply-filter').addEventListener('click', function() {
            const nodeFilter = document.getElementById('node-filter').value;
            const nodeType = document.getElementById('node-type').value;
            const complexityThreshold = 
                document.getElementById('complexity-threshold').value;
            
            // 触发过滤事件
            window.dispatchEvent(new CustomEvent('applyFilter', {
                detail: {
                    node: nodeFilter,
                    type: nodeType,
                    complexity: parseInt(complexityThreshold)
                }
            }));
        });
        
        document.getElementById('reset-filter').addEventListener('click', function() {
            document.getElementById('node-filter').value = '';
            document.getElementById('node-type').value = 'all';
            document.getElementById('complexity-threshold').value = '10';
            
            // 触发重置事件
            window.dispatchEvent(new CustomEvent('resetFilter'));
        });
        
        // 更新指标
        function updateMetrics(metrics) {
            document.getElementById('total-nodes').textContent = metrics.totalNodes;
            document.getElementById('condition-branches').textContent = 
                metrics.conditionBranches;
            document.getElementById('loop-count').textContent = metrics.loopCount;
            document.getElementById('avg-complexity').textContent = 
                metrics.avgComplexity.toFixed(2);
        }
        
        // 监听指标更新事件
        window.addEventListener('metricsUpdate', function(event) {
            updateMetrics(event.detail);
        });
    </script>
</body>
</html> 